package com.ambow.common;

import java.io.Serializable;

public class ResponseBean<T> implements Serializable {
	/**
	 * 
	 */
	private static final long serialVersionUID = 4421244886009834860L;
	private int status = 0;
	private String msg;
	private T data;
	
	private ResponseBean(int status){
        this.status = status;
    }
    private ResponseBean(int status,T data){
        this.status = status;
        this.data = data;
    }
    private ResponseBean(int status,String msg,T data){
        this.status = status;
        this.msg = msg;
        this.data = data;
    }
    private ResponseBean(int status,String msg){
        this.status = status;
        this.msg = msg;
    }
    
    public boolean isSuccess(){
    	return this.status == ResponseCode.SUCCESS.getCode();
    }
    public int getStatus() {
        return status;
    }
    public T getData() {
        return data;
    }
    public String getMsg() {
        return msg;
    }
    public static <T> ResponseBean<T> createBySuccess(){
		return new ResponseBean<T>(ResponseCode.SUCCESS.getCode());
    }
    public static <T> ResponseBean<T> createBySuccess(T data){
    	return new ResponseBean<T>(ResponseCode.SUCCESS.getCode(),data);
    }
    public static <T> ResponseBean<T> createBySuccess(String msg,T data){
    	return new ResponseBean<T>(ResponseCode.SUCCESS.getCode(),msg,data);
    }
    public static <T> ResponseBean<T> createBySuccessMessage(String msg){
    	return new ResponseBean<T>(ResponseCode.SUCCESS.getCode(),msg);
    }
    public static <T> ResponseBean<T> createByError(){
        return new ResponseBean<T>(ResponseCode.ERROR.getCode(),ResponseCode.ERROR.getDesc());
    }
    public static <T> ResponseBean<T> createByErrorMessage(String errorMessage){
        return new ResponseBean<T>(ResponseCode.ERROR.getCode(),errorMessage);
    }
    public static <T> ResponseBean<T> createByErrorCodeMessage(int errorCode,String errorMessage){
        return new ResponseBean<T>(errorCode,errorMessage);
    }
	
}
